#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020/4/29 14:31
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : sms_test.py
# @Software: PyCharm

__author__ = 'yangdy'

from base64 import decode

import requests


def main():
    _SPID = '010008'
    _PASS = 'y7odFwI4'
    _PREFIX = 'http://116.255.246.227:27504/smsgwhttp/'
    _URLS = {
        'smsgwhttp': 'http://116.255.246.227:27504/smsgwhttp/',
        'submit-ac': 'sms/submit/?spid={SPID}&password={PASS}&mobiles={MOBILES}&content={CONTENT}&ac={AC}',
        'submit': 'sms/submit/?spid={SPID}&password={PASS}&mobiles={MOBILES}&content={CONTENT}',
    }

    def make_url(key, params):
        _url = _URLS[key].format(
            SPID=_SPID, PASS=_PASS,
            MOBILES=params['mobiles'],
            CONTENT=params['content'],
            AC=params['ac'] if params.get('ac') else ''
        )
        return _PREFIX + _url
    mobiles = '13782008378'
    content = u'【中关村e谷】hello，this is a nice day ！'
    params = {
        'mobiles': mobiles,
        'content': content,
        'ac': '010008'
    }
    url = make_url('submit', params)
    # print('url', url)
    res = requests.post(url=url)
    print(res)
    # print(res.content)
    text = res.content.decode('utf-8')
    print(text)
    url_ac = make_url('submit-ac', params)
    # print('url-ac', url_ac)
    res = requests.get(url=url_ac)
    print(res)
    print(res.content.decode('utf-8'))


if __name__ == '__main__':
    main()

